<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
set_time_limit(0);
$strWeb = $_SERVER[argv][1];

$_Email = "pinus@uuss.net";
$_Subject = " Every Day Clean Old Data Error!! (".$strWeb.")";

$isError = false;
$strLogError = $strWeb."  Time: ".date("Y-m-d H:i:s")."\n";
$_DBSite = "Master";
$_isDBExist = "no";

$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/".$strWeb."/secure";
include("/home/share/www/SourceSite-utf8/secure/config.inc.php");
include(__Root_Path."/config.inc.php");
include(__DBConnect_File);
if($_strLogErr != ""){
	$strContent = $strLogError.$_strLogErr;
	mail($_Email, $_Subject, $strContent, "From:".$strWeb."<apache@secure.".$strWeb.">");
	exit($strLogError.$_strLogErr);
}
include(__Modules_Path."/UserSessions.lib.php");
include(__Modules_Path."/Marquee.lib.php");
include(__Modules_Path."/Competition.lib.php");

//清除昨日以前暫存注單
if(!rmCompetitionEndLastDayData(0)){
	$strLogError .= $GLOBALS["errormessage"]."\n";
	$strLogError .= $GLOBALS["errorhidden"]."\n";
	$isError = true;
}else{
	$strLogError .= "Delete BetListTmp ".$Yesterday." Data OK!<br>\n";
}

//清除Session
UserSession_End("", 0);
UserSession_Clear();
$strSQL = "ALTER TABLE `bet_Sessions` TYPE = HEAP ";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	$strLogError .= "ALTER TABLE `bet_Sessions` Error!<br>\n";
	$strLogError .= "SQL: ".$strSQL.", \nError: ".PMA_mysql_error($_ConnMaster).", \nLine: ".__LINE__.", \nPage: ".__FILE__."<br>\n";
	$isError = true;
}else{
	$strLogError .= "ALTER TABLE `bet_Sessions` OK!<br>\n";
}
$strLogError .= "Clear Session OK!<br>\n";

//更新走馬燈檔案
if(!MakeMarquee()){
	$strLogError .= $GLOBALS["errormessage"]."\n";
	$strLogError .= $GLOBALS["errorhidden"]."\n";
	$isError = true;
}else{
	$strLogError .= "Clear NumberEven OK!<br>\n";
}

//刪除兩個月前的紀錄
$strSQL = "DELETE FROM `bet_LogRecord` WHERE `ActionDate` < '".date("Y-m-d", mktime(0, 0, 0, $arrD[1] - 2, $arrD[2], $arrD[0]))."'";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	$strLogError .= "DELETE TABLE `bet_LogRecord` Error!<br>\n";
	$strLogError .= "SQL: ".$strSQL.", \nError: ".PMA_mysql_error($_ConnMaster).", \nLine: ".__LINE__.", \nPage: ".__FILE__."<br>\n";
	$isError = true;
}else{
	$strLogError .= "DELETE TABLE `bet_LogRecord` OK!<br>\n";
	PMA_mysql_query("OPTIMIZE TABLE `bet_LogRecord`", $_ConnMaster);
}
$strLogError .= "DELETE LogRecord OK!<br>\n";


//清除Bet Control
$strSQL = "ALTER TABLE `bet_BetControl` TYPE = HEAP ";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	$strLogError .= "TRUNCATE Bet Control Error!<br>\n";
	$strLogError .= "SQL: ".$strSQL.", \nError: ".PMA_mysql_error($_ConnMaster).", \nLine: ".__LINE__.", \nPage: ".__FILE__."<br>\n";
	$isError = true;
}else{
	$strLogError .= "TRUNCATE Bet Control OK!<br>\n";
}
$strLogError .= "TRUNCATE Bet Control OK!<br>\n";

if($isError){
	$strContent = $strLogError;
	mail($_Email, $_Subject, $strContent, "From:".$strWeb."<apache@secure.".$strWeb.">");
}
$strLogError .= $strWeb."  Time: ".date("Y-m-d H:i:s")." End\n\n";
@mysql_close($$_Conn);
print $strLogError;
?>